Socket
Socket
Sign inDemoInstall

revalidator

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

revalidator

A cross-browser / node.js validator used by resourceful


Version published
Weekly downloads
439K
decreased by-16.29%
Maintainers
5
Weekly downloads
 
Created

What is revalidator?

The revalidator npm package is a versatile tool for validating JavaScript objects against a defined schema. It supports a wide range of validation rules and custom validation logic, making it suitable for various data validation needs.

What are revalidator's main functionalities?

Basic Schema Validation

This feature allows you to define a schema with various properties and validate an object against it. The code sample demonstrates how to validate a person's name and age.

const revalidator = require('revalidator');

const schema = {
  properties: {
    name: {
      description: 'Name of the person',
      type: 'string',
      required: true,
      minLength: 2
    },
    age: {
      description: 'Age of the person',
      type: 'integer',
      minimum: 0
    }
  }
};

const person = { name: 'John', age: 30 };
const result = revalidator.validate(person, schema);
console.log(result);

Custom Validation

This feature allows you to add custom validation logic using the 'conform' function. The code sample shows how to validate a password to ensure it is at least 8 characters long.

const revalidator = require('revalidator');

const schema = {
  properties: {
    password: {
      description: 'User password',
      type: 'string',
      conform: function (value) {
        return value.length >= 8;
      },
      messages: {
        conform: 'Password must be at least 8 characters long'
      }
    }
  }
};

const user = { password: 'short' };
const result = revalidator.validate(user, schema);
console.log(result);

Nested Object Validation

This feature supports validation of nested objects. The code sample demonstrates how to validate an address object within a person object.

const revalidator = require('revalidator');

const schema = {
  properties: {
    address: {
      type: 'object',
      properties: {
        street: { type: 'string', required: true },
        city: { type: 'string', required: true }
      }
    }
  }
};

const person = { address: { street: '123 Main St', city: 'Anytown' } };
const result = revalidator.validate(person, schema);
console.log(result);

Other packages similar to revalidator

FAQs

Package last updated on 29 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc